

Promise.prototype.myCatch = function (onRejected) {

    return this.then(null,onRejected)
}

let rejectedPromise = new Promise((resolve, reject) => {
    reject('Something went wrong!');
});
let rejectedPromise2 = new Promise((resolve, reject) => {
    resolve('Something went wrong!');
});
rejectedPromise
    // then可以在成功和失败时调用(两个参数) 而catch只捕获失败。
    // 即上一步then中已经处理了reject 返回一个Promise 这个promise呈pending状态 所以不会触发.catch
    .then(() => console.log('Resolved!'))
    .myCatch(error => console.log(`Rejected with error: ${error}`));
